package com.cjyd.hrjb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cjyd.hrjb.mapper.UserMapper;
import com.cjyd.hrjb.model.dto.AppData;
import com.cjyd.hrjb.model.entity.User;
import com.cjyd.hrjb.service.AppDataService;
import com.cjyd.hrjb.utils.DateUtil;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;

/**
 * Created fei wo by 2020/4/9
 */
@Service
public class AppDataServiceImpl implements AppDataService {

    private final UserMapper userMapper;

    public AppDataServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public AppData getAppData() {
        LambdaQueryWrapper<User> queryWrapper = Wrappers.<User>lambdaQuery()
                .le(User::getCreatedAt, DateUtil.todayEndDate())
                .ge(User::getCreatedAt, DateUtil.todayBeginDate());
        Integer count = userMapper.selectCount(queryWrapper);
        Integer totalCount = userMapper.selectCount(Wrappers.emptyWrapper());
        AppData appData = new AppData();
        appData.setTodayNewUserCount(count);
        appData.setTotalUserCount(totalCount);
        return appData;
    }
}
